package com.gemme.gemme.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.gemme.gemme.R;

public class Interest2View extends RelativeLayout {
    private Context context;
    private OnChangeLIstener onChangeLIstener;

    public Interest2View(Context context) {
        this(context,null);
    }

    public Interest2View(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public Interest2View(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        this.context = context;
        initView();
    }
    ImageView iv_picture;
    TextView tv;
    ImageView iv_checkBox;
    boolean isCheck = false;
    private void initView() {
        LayoutInflater.from(context).inflate(R.layout.item_interest2,this);

        iv_picture = findViewById(R.id.iv_picture);

        tv = findViewById(R.id.tv);


        iv_checkBox = findViewById(R.id.iv_checkBox);
        changeState();
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                isCheck = !isCheck;
                if(onChangeLIstener != null){
                    onChangeLIstener.onChangeLIstener();
                }

                changeState();
            }
        });
    }

    public String getName(){
        return tv.getText() + "";
    }

    public boolean getState(){
        return isCheck;
    }

    private void changeState() {
        if(isCheck){
            iv_checkBox.setVisibility(VISIBLE);
        }else{
            iv_checkBox.setVisibility(GONE);
        }
    }

    public Interest2View setPicture(String url){
        Glide.with(context).load(url).into(iv_picture);
        return this;
    }

    public Interest2View setText(String str){
        tv.setText(str + "");
        return this;
    }


    public void setOnChangeLIstener(OnChangeLIstener onChangeLIstener){

        this.onChangeLIstener = onChangeLIstener;
    }

}
